package com.kwm.Controller;
import com.kwm.Service.impl.EmpServiceimpl;
import com.kwm.entity.Emp;
import com.kwm.entity.EmpQueryParam;
import com.kwm.entity.PageBean;
import com.kwm.entity.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RestController
public class EmpController {
    @Autowired
    private EmpServiceimpl empService;

    @GetMapping("/emps")
    public Result page(EmpQueryParam param) {
        log.info("请求参数： {}", param);
        PageBean pageBean = empService.page(param);
        return Result.success(pageBean);
    }

    @PostMapping("/emps")
    public Result add(@RequestBody Emp emp){
        log.info("请求参数为{}，",emp);
        empService.add(emp);
        return Result.success();
    }
    @DeleteMapping("/emps")
    public Result delete(@RequestParam List<Integer> ids){
        empService.delete(ids);

        return Result.success();
    }
    @GetMapping("/emps/{id}")
    public Result getByid(@PathVariable Integer id){
        Emp emp = empService.getId(id);
        return Result.success(emp);
    }
    @PutMapping("/emps")
    public Result update(@RequestBody Emp emp){

        empService.update(emp);

        return Result.success();
    }

}
